"use strict";
var Queue = /** @class */ (function () {
    function Queue() {
        this.items = {};
        this.front = 0;
        this.rear = 0;
    }
    //  入队
    Queue.prototype.enqueue = function (element) {
        this.items[this.rear++] = element;
    };
    // 出队
    Queue.prototype.dequeue = function () {
        if (!this.isEmpty()) {
            var element = this.items[this.front];
            delete this.items[this.front++];
            return element;
        }
        else {
            console.warn('队列已经空啦！');
        }
    };
    Queue.prototype.peek = function () {
        return this.items[this.front];
    };
    Queue.prototype.isEmpty = function () {
        return this.size() === 0;
    };
    Queue.prototype.size = function () {
        return this.rear - this.front;
    };
    return Queue;
}());
var DQueuq = /** @class */ (function () {
    function DQueuq() {
        this.items = {};
        this.front = 0;
        this.rear = 0;
    }
    //  从前端添加
    DQueuq.prototype.addFront = function (element) {
        //  若队列为空， 则直接加在队尾
        if (this.isEmpty()) {
            this.addRear(element);
        }
        //  若 队首指针大于0 则 队首指针前移一位添加元素
        else if (this.front > 0) {
            this.items[--this.front] = element;
        }
        //  若 队尾指针等于0 则将队列元素全部后移一位，将元素添加到队尾
        else {
            for (var index = this.size(); index > 0; index--) {
                this.items[index] = this.items[index - 1];
            }
            this.rear++;
            this.items[this.front] = element;
        }
    };
    //  从后端添加
    DQueuq.prototype.addRear = function (element) {
        this.items[this.rear++] = element;
    };
    //  从前端删除
    DQueuq.prototype.deFront = function () {
        if (!this.isEmpty()) {
            var element = this.items[this.front];
            delete this.items[this.front++];
            return element;
        }
        else {
            console.warn('队列已经空啦！');
        }
    };
    //  从后端删除
    DQueuq.prototype.deBack = function () {
        if (!this.isEmpty()) {
            var element = this.items[--this.rear];
            delete this.items[this.rear];
            return element;
        }
        else {
            console.warn('队列已经空啦！');
        }
    };
    //  队列是否为空
    DQueuq.prototype.isEmpty = function () {
        return this.size() === 0;
    };
    //  队列长度
    DQueuq.prototype.size = function () {
        return this.rear - this.front;
    };
    //  队首元素
    DQueuq.prototype.peekFront = function () {
        if (this.isEmpty()) {
            console.warn('队列已经么有元素啦！');
        }
        else {
            return this.items[this.front];
        }
    };
    //  队尾元素
    DQueuq.prototype.peekRear = function () {
        if (this.isEmpty()) {
            console.warn('队列已经么有元素啦！');
        }
        else {
            return this.items[this.rear - 1];
        }
    };
    return DQueuq;
}());
function hotPotato(list, number) {
    var queue = new Queue();
    list.forEach(function (item) {
        queue.enqueue(item);
    });
    while (queue.size() > 1) {
        for (var index = 1; index <= number; index++) {
            var item = queue.dequeue();
            queue.enqueue(item);
        }
        queue.dequeue();
    }
    return {
        winner: queue.dequeue()
    };
}
function palindromeChecker(str) {
    if (!str) {
        return '';
    }
    str = str.toLocaleLowerCase().split('  ').join('');
    var strDQueue = new DQueuq();
    Array.from(str).forEach(function (item) {
        strDQueue.addRear(item);
    });
    while (!strDQueue.isEmpty()) {
        if (strDQueue.peekFront() != strDQueue.peekRear()) {
            console.log(str + "\u4E0D\u662F\u56DE\u6587!");
            return false;
        }
        strDQueue.deFront();
        strDQueue.deBack();
    }
    console.log(str + "\u662F\u56DE\u6587!");
}
palindromeChecker('a');
palindromeChecker('kayak');
palindromeChecker('level');
palindromeChecker('Was it a car or a cat I saw');
palindromeChecker('Step on no pets');
